<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="/person/css/common.css"/>
    <script type="text/javascript" src="/person/js/jquery.1.9.1.js" ></script>
   <script type="text/javascript" src="/plan/js/layer.js" ></script>
   <script type="text/javascript" src="/person/js/multiple-select.js" ></script>
    <link rel="stylesheet" type="text/css" href="/person/css/multiple-select.css"/>
	<script type="text/javascript" src="/person/js/rem.js" ></script>
	      <script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
	<script src="https://cdn.bootcss.com/vConsole/3.2.0/vconsole.min.js"></script> 	     
    <title>人员信息</title>
</head>
<body>
	<ul class="order_money" style="padding: 0 0.3rem;background: #fff;">
		<li>
	    		<span class="fontchang">{:__('Userid')}</span>
	    		<div class="choose">
				<div id="divclass" style="display: none;">
					<img src="" id="avatar"/>
					<img class="close" src="/person/img/close.png" />
					<p id="username"></p>
					<input type="hidden"  id="nameuserid" />
				</div>
				<div>
					<img  id="updateuserid" src="/person/img/addwl.png" />
				</div>
			</div>
	   </li> 
	  <li style="padding-bottom: 0;height: 1.1rem;position: relative;">
			<span class="type">{:__('User.Position')}</span><span class="jt" style="margin-top: 0.15rem;"></span>
			 <span class="bitian1">必填</span>
			   {:build_select('position[]', $WeekInfo['position_data'], null, ['class'=>'form-control selectpicker', 'multiple'=>'multiple', 'data-rule'=>'required'])}
			<input type="hidden" name="" id="type" value="" />								
		</li>
	    <li>
	    		<span class="fontchang">{:__('User.Proportion')}</span>
	    		<!--<span class="must">必填</span>-->
	    		<input type="number" name="" id="percent"  />
	    		<p class="percent_warn">{:__('User.Note')}</p>
	    			<!-- <span class="help-block" style="font-size: 0.2rem;color: #c2c2c2;">{:__('User.Note')}</span> -->
	    </li>
	    <li>
	    		<span class="fontchang">{:__('User.Admission_fee')}</span>
	    		<!--<span class="must">必填</span>-->
	    		<input type="number" name="" id="fee" />
	    </li>
	    <li>
	    		<span class="fontchang">{:__('Desc')}</span>
	    		<textarea id="beizhu" value=""></textarea>
	    </li>
	</ul>
	<div class="preserve">保存</div>
</body>
<script>
let vConsole = new VConsole();
 wx.config({$json});
 wx.checkJsApi({
    jsApiList: ['selectEnterpriseContact','openEnterpriseChat'], // 需要检测的JS接口列表，所有JS接口列表见附录2,
    success: function(res) {
        // 以键值对的形式返回，可用的api值true，不可用为false
        // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
    }
});
wx.ready(function(){
	var nameuserid = '';
  $(document).on('click', "#updateuserid", function () {
     var id = $(this).attr("attrid");
       wx.invoke("selectEnterpriseContact", {
                "fromDepartmentId": {$info.department},// 必填，-1表示打开的通讯录从自己所在部门开始展示, 0表示从最上层开始
                "mode": "single",// 必填，选择模式，single表示单选，multi表示多选
                "type": ["user"],// 必填，选择限制类型，指定department、user中的一个或者多个
                "selectedDepartmentIds": [],// 非必填，已选部门ID列表。用于多次选人时可重入
                "selectedUserIds": [nameuserid]// 非必填，已选用户ID列表。用于多次选人时可重入
            },function(res){
                if (res.err_msg == "selectEnterpriseContact:ok")
                {
                    if(typeof res.result == 'string')
                    {
                        alert('不兼容');
                        res.result = JSON.parse(res.result) //由于目前各个终端尚未完全兼容，需要开发者额外判断result类型以保证在各个终端的兼容性
                    }
                    var selectedDepartmentList = res.result.departmentList;// 已选的部门列表
                    for (var i = 0; i < selectedDepartmentList.length; i++)
                    {
                        var department = selectedDepartmentList[i];
                        var departmentId = department.id;// 已选的单个部门ID
                        var departemntName = department.name;// 已选的单个部门名称
                    }
                    var selectedUserList = res.result.userList; // 已选的成员列表
                    for (var i = 0; i < selectedUserList.length; i++)
                    {

                        var user = selectedUserList[i];
                        var userId = user.id; // 已选的单个成员ID
                        var userName = user.name;// 已选的单个成员名称
                        var userAvatar= user.avatar;// 已选的单个成员头像
                    }
                  $("#avatar").attr("src", userAvatar);
                  $("#nameuserid").val(userId);
                  nameuserid = userId;
                  $("#username").text(userName);
                  $("#updateuserid").hide();
                  $("#divclass").show();
                  //获取职位
                  	$.ajax({
					  type: 'post',
					  url: '/api/base/position_new',
					  data:{userid:userId},
					  dataType: "json",
					  success: function(data){
					  		if(data.code){
					  			$('.selectpicker').val('');
						  		console.log(data);
						  			$(".selectpicker").fSelect('destroy');
 									$(".selectpicker").val(data.data);
									$(".selectpicker").fSelect('create');
									$('.type').css('font-size','0.2rem');
							}
					  		
					  }
					});
                }
            }
        );
  });
});
</script>
<script>
$(function(){
	$(".selectpicker").fSelect();
	$('.close').click(function(){
		$(this).parent().hide();
		$(this).parent().siblings().css('margin-left','0');
		$(this).parent().siblings().children().show();
	});
	//提交表单
	$('.preserve').click(function(){
		var name = $('#nameuserid').val();
		var job = $('.selectpicker').val();
		var percent = $('#percent').val();
		var fee = $('#fee').val();
		var beizhu = $('#beizhu').val();
		if(name == ''||name == null){
			layer.open({
				content:'请选择人员' ,
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false;
		}
		if(job == ''||job == null){
				layer.open({
				content:'请选择职位' ,
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false;
		}
		if(percent > 100){
			layer.open({
				content:'分成百分比不能超过100' ,
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false;	
		}
		var index = layer.open({type: 2});
		$.ajax({
		  type: 'post',
		  url:"",
		  data:{userid:name,position:job,proportion:percent,admission_fee:fee,desc:beizhu},
		  dataType: "json",
		  success: function(data){
		  		console.log(data);
		  		layer.open({
						content:data.msg,
						skin: 'msg',
						time: 2 //2秒后自动关闭
				});
				layer.close(index);
			  	if(data.code){
			  		 setTimeout(function () {
						window.location.href = "/index/plan/public_view/type/User/ids/"+data.data;
					},2000);
			  	}
		  }
		});
	 });
	 //字体变化
	$('input').keyup(function(){
		if($(this).val() != ''){
			$(this).siblings('.must').hide();
			$(this).siblings('.fontchang').css('font-size','0.2rem');
		}else{
			$(this).siblings('.must').show();
			$(this).siblings('.fontchang').css('font-size','0.32rem');
		}
	});
	if($('#userid').val() != ''){
		$('#userid').parents('.choose').siblings('.fontchang').css('font-size','0.2rem');
	}else{
		$('#userid').parents('.choose').siblings('.fontchang').css('font-size','0.32rem');
	}
	$('.queding').click(function(){
		if($('.selectpicker').val() != null){
			$('.type').css('font-size','0.2rem');
			$('.bitian1').hide();
		}else{
			$('.type').css('font-size','0.32rem');
			$('.bitian1').show();
		}

	});

	$('#clearAllBtn').click(function(){
		$('.type').css('font-size','0.32rem');
		$('.bitian1').show();
	});
	$('textarea').keyup(function(){
		if($(this).val() != ''){
			$(this).siblings('.must').hide();
			$(this).siblings('.fontchang').css('font-size','0.2rem');
		}else{
			$(this).siblings('.must').show();
			$(this).siblings('.fontchang').css('font-size','0.32rem');
		}
	});
});
</script>
</html>
